package com.rayo.accesscontrollercopy.model.db.bean;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.litesuits.orm.db.annotation.Table;
import com.rayo.accesscontrollercopy.config.NetworkConfig;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by yanghaojie on 16/7/27.
 */
@Table("dst_table")
public class DSTData extends BaseModel {
    private int enable;

    @JSONField(format= NetworkConfig.JSON_DATE)
    private Date begin;

    @JSONField(format= NetworkConfig.JSON_DATE)
    private Date end;

    public DSTData() {
        this.begin = new Date();
        this.end = new Date();
        this.editime = new Date();
    }

    public Date getBegin() {
        return begin;
    }

    public void setBegin(Date begin) {
        this.begin = begin;
    }

    public Date getEnd() {
        return end;
    }

    public void setEnd(Date end) {
        this.end = end;
    }

    public static DSTData formJsonStr(String data){
        DSTData dSTData;
        try {
            dSTData = JSON.parseObject(data, DSTData.class);
            JSONObject obj = JSON.parseObject(data);
            SimpleDateFormat dateformat = new SimpleDateFormat(NetworkConfig.JSON_DATE_HOUR);
            dSTData.setBegin(dateformat.parse(obj.getString("begin")));
            dSTData.setEnd(dateformat.parse(obj.getString("end")));
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return dSTData;
    }

    public int getEnable() {
        return enable;
    }

    public void setEnable(int enable) {
        this.enable = enable;
    }
}
